package strings

import (
	"strconv"
	"strings"
)

func Str2Int64(str string)  (result int64) {
	str = strings.ReplaceAll(str,",","")
	if strings.Contains(str,".") {
		result,_ = strconv.ParseInt(strings.Split(str,".")[0],10,64)
	}else {
		result, _ = strconv.ParseInt(str, 10, 64)
	}
	return
}

func Substr(str string, start, length int) string {
	if length == 0 {
		return ""
	}
	rune_str := []rune(str)
	len_str := len(rune_str)

	if start < 0 {
		start = len_str + start
	}
	if start > len_str {
		start = len_str
	}
	end := start + length
	if end > len_str {
		end = len_str
	}
	if length < 0 {
		end = len_str + length
	}
	if start > end {
		start, end = end, start
	}
	return string(rune_str[start:end])
}
